<div id="tb<?php echo $uniqid;?>" style="padding:5px">
	<table cellspacing="0" cellpadding="0">
		<tbody>
		<tr>
			<td><a href="javascript:void(0);" onclick="stockwarningEdit();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-bianji"></i><span class="l-btn-text">补货</span></span></a></td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td><a href="javascript:void(0);" onclick="stockwarningReload();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span class="l-btn-text">重载</span></span></a></td>
			<td>&nbsp;&nbsp;<input id="stockwarningKeywords" style="width:100px" type="text"
								  class="easyui-input textbox"></td>
			<td><a href="javascript:void(0);" onclick="stockwarningSearch();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span class="l-btn-text">查询</span></span></a></td>
		</tr>
		</tbody>
	</table>
</div>
<div class="con"  style="-moz-user-select:none;">
	<table id="stockwarning"></table>
</div>
<div id="stockwarningDlg" class="easyui-dialog" style="width:720px; height:520px;" title="信息框" closed="true"></div>
<script>	
	var cpfr = function (id) {
		let rowId = id || ($('#stockwarning').datagrid('getSelected') && $('#stockwarning').datagrid('getSelected').id);
		if (rowId) {
			$("#stockwarningDlg").dialog({
				title: '编辑信息',
				closed: false,
				width: 740,
				height: 520,
				cache: false,
				href: '/merchant/goods/cpfr?id=' + rowId,
				modal: true,
				buttons: [{
					text: '保存',
					id: 'stockwarningsubmit',
					iconCls: 'icon-ok',
				}, {
					text: '关闭',
					iconCls: 'icon-no',
					handler: function () {
						$("#stockwarningDlg").dialog('close');
					}
				}]
			});
		} else {
			$.messager.alert('提示', '请先选择要编辑的行！', 'warning');
		}
	};
	var stockwarningReload = function () {
		$("#stockwarning").datagrid('reload');
	};
	var stockwarningSearch = function () {
		var height = $(window).height() - $(".top").height() - 46;
		var width = $(window).width() - $(".leftmenu").width() - 8;
		$("#stockwarning").datagrid({
			title: '库存预警',
			width: width,
			height: height,//高度
			singleSelect: true,//如果为true，则只允许选择一行
			striped: true,//是否显示斑马线效果。
			rownumbers: false,//如果为true，则显示一个行号列。
			pagination: true,//是否显示分页
			pageSize: 10,
			pageList: [10, 15, 20, 25],
			method: 'post',
			sortName: 'id',
			sortOrder: 'desc',
			idField: 'id',
			treeField: 'title',
			url: '/merchant/goods/stockwarning',
			queryParams: {keywords: $('#stockwarningSearch').val()},
			fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
			nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
			selectOnCheck: false,
			checkOnSelect: true,
			toolbar: '#tb<?php echo $uniqid;?>',
			columns: [[
				{field:'goods_id',title:'商品ID',width:'5%'},
				{field:'title',title:'商品',width:'30%'},
				{field:'goods_sku_text',title:'商品规格',width:'20%'},
				{field:'stock',title:'库存',width:'7%', align:'center'},
				{field:'stock_warning',title:'预警阀值', align:'center', width:'10%', formatter(value, rowData){
					return value ? value : '<?php echo $threshold;?>';
					}},
				{field:'updated_at',title:'更新时间',width:'7%'},
				{field:'status',title:'状态',width:'5%',formatter:function (value,rowData,rowIndex){
						return value==='show' ? '已上架' : '已下架';
					},styler(value, rowData){
						return value==='show' ? 'color:green' : 'color:red';
					}},
				{
					field: 'options',
					title: '操作',
					align: 'center',
					width: '6%',
					formatter: function (value, rowData, rowIndex) {
						let buttons = '<div class="table"><span class="l-btn l-btn-small color9 table" onclick="cpfr(\'' + rowData.id + '\')"><span class="l-btn-text">补货</span></span>';
						return buttons + '</div>';
					}
				},
			]],
			onDblClickRow: function (index, field) {
				stockwarningEdit();
			}
		});
	};
	onDatagridResize("#stockwarning");
	stockwarningSearch();
</script>
